home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / stdwin / Ports / x11 / scroll.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-03  |  2.9 KB  |  115 lines  |  [TEXT/????]

  1. /* X11 STDWIN -- Scroll bars */
  2.  
  3. #include "x11.h"
  4.  
  5. #define IMARGIN 2 /* See window.c */
  6.  
  7. /* Macro to compute the thumb position and size.
  8.    Don't call when docwidth (docheight) is zero. */
  9.  
  10. /* dir is x or y; dim is width or height; bar is hbar or vbar */
  11. #define BARCOMPUTE(dir, dim, bar) { \
  12.         range= win->bar.dim; \
  13.         start= range * (-win->wa.dir) / win->doc.dim; \
  14.         size= range * win->wi.dim / win->doc.dim; \
  15.         _wdebug(4, "BARCOMPUTE: start=%d, size=%d", start, size); \
  16.     }
  17.  
  18. /* Functions to draw the scroll bars.
  19.    Currently, the thumb is a rectangle separated by the scroll bar's
  20.    borders by a one-pixel wide space */
  21.  
  22. _wdrawhbar(win)
  23.     WINDOW *win;
  24. {
  25.     if (win->hbar.wid == None)
  26.         return;
  27.     _wdebug(3, "draw hbar");
  28.     XClearWindow(_wd, win->hbar.wid);
  29.     if (win->doc.width > win->wi.width) {
  30.         int start, size, range;
  31.         BARCOMPUTE(x, width, hbar);
  32.         XSetTile(_wd, win->gc, _w_gray());
  33.         XSetFillStyle(_wd, win->gc, FillTiled);
  34.         XFillRectangle(_wd, win->hbar.wid, win->gc,
  35.             start + 1, 1, size - 1, win->hbar.height - 2);
  36.         XSetFillStyle(_wd, win->gc, FillSolid);
  37.     }
  38. }
  39.  
  40. _wdrawvbar(win)
  41.     WINDOW *win;
  42. {
  43.     if (win->vbar.wid == None)
  44.         return;
  45.     _wdebug(3, "draw vbar");
  46.     XClearWindow(_wd, win->vbar.wid);
  47.     if (win->doc.height > win->wi.height) {
  48.         int start, size, range;
  49.         BARCOMPUTE(y, height, vbar);
  50.         XSetTile(_wd, win->gc, _w_gray());
  51.         XSetFillStyle(_wd, win->gc, FillTiled);
  52.         XFillRectangle(_wd, win->vbar.wid, win->gc,
  53.             1, start + 1, win->vbar.width - 2, size - 1);
  54.         XSetFillStyle(_wd, win->gc, FillSolid);
  55.     }
  56. }
  57.  
  58. /* Functions to interpret scroll bar hits.
  59.    Matching the Toolkit scroll bars, we should implement:
  60.    - button 1: scroll forward, amount determined by position
  61.    - button 2: position scroll bar begin at pointer
  62.    - buttom 3: scroll back, amount determined by position
  63. */
  64.  
  65. /* dir is x or y; dim is width or height; bar is hbar or vbar;
  66.    drawcall is _wdraw{h,v}bar; imargin is IMARGIN or 0. */
  67. #define HITCODE(dir, dim, bar, drawcall, imargin) { \
  68.         WINDOW *win= bsp->win; \
  69.         int start, size, range, nstart; \
  70.         if (win->doc.dim <= win->wi.dim - imargin) \
  71.             return; \
  72.         BARCOMPUTE(dir, dim, bar); \
  73.         switch (bsp->button) { \
  74.         case 1: \
  75.             if (bsp->down) return; \
  76.             nstart= start + \
  77.                 (bsp->dir * win->wi.dim + win->doc.dim/2) \
  78.                     / win->doc.dim; \
  79.             break; \
  80.         default: \
  81.             nstart= bsp->dir; \
  82.             break; \
  83.         case 3: \
  84.             if (bsp->down) return; \
  85.             nstart= start - \
  86.                 (bsp->dir * win->wi.dim + win->doc.dim/2) \
  87.                     / win->doc.dim; \
  88.             break; \
  89.         } \
  90.         CLIPMAX(nstart, range-size); \
  91.         CLIPMIN(nstart, 0); \
  92.         if (nstart != start) { \
  93.             win->wa.dir= \
  94.                 -(nstart * win->doc.dim / win->bar.dim); \
  95.             _wmove(&win->wa); \
  96.             drawcall(win); \
  97.         } \
  98.     }
  99.  
  100. _whithbar(bsp, ep)
  101.     struct button_state *bsp;
  102.     EVENT *ep;
  103. {
  104.     _wdebug(3, "hit hbar");
  105.     HITCODE(x, width, hbar, _wdrawhbar, IMARGIN);
  106. }
  107.  
  108. _whitvbar(bsp, ep)
  109.     struct button_state *bsp;
  110.     EVENT *ep;
  111. {
  112.     _wdebug(3, "hit vbar");
  113.     HITCODE(y, height, vbar, _wdrawvbar, 0);
  114. }
  115.